#pragma once

#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <fstream>
using namespace std;

#include "room.h"

class building
{
protected:
	vector<room> v;
	string info;
public:

	building()
	{
	}

	building(string info)
	{
		this->info = info;
	}

	~building()
	{
	}

	string getInfo()
	{
		return info;
	}
	
	void setInfo(string info)
	{
		this->info = info;
	}

	void add(room r)
	{
		v.push_back(r);
	}

	vector<room>::iterator search(room r)
	{
		vector<room>::iterator it = find(v.begin(), v.end(), r);
		return it;		
	} 

	void remove(room r)
	{
		vector<room>::iterator it = search(r);
		v.erase(it);
	}

	string list()
	{
		ostringstream oss;
		string list;
		for (int i = 0; i < v.size(); i++){
			oss << v[i] << endl;
		}

		list = oss.str();
		return list;
	}

	void writeToFile(string filename)
	{
		ofstream fout(filename);
		fout << list();
	}

	void readFromFile(string filename){
		ifstream in(filename);
		room r;
		while (in >> r){
			v.push_back(r);
		}
	}

	double area(){
		double area = 0;
		for (int i = 0; i < v.size(); i++){
			area += v[i].getArea();
		}
		return area;
	}

	void clear()
	{
		v.clear();
	}

	virtual void print(){
		cout << "Info = " << info << endl;
		cout << "Rooms: " << endl;
		cout << list();
		
	}

};

